ProfileHeader.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. "use client";
  2. import { GameListRep, GameRequest } from "@/api/home";
  3. import { userInfoApi } from "@/api/login";
  4. import {
  5. UserInfoRep,
  6. UserVipInfo,
  7. Wallet,
  8. cleanBounsApi,
  9. getUserMoneyApi,
  10. getUserTransferApi,
  11. } from "@/api/user";
  12. import {
  13. BalanceContent,
  14. BonusContent,
  15. FreeContent,
  16. ReplayContent,
  17. } from "@/components/ModalPopup/WalletDescribeModal";
  18. import TipsModal, { ModalProps } from "@/components/TipsModal";
  19. import useGame from "@/hooks/useGame";
  20. import { Link, useRouter } from "@/i18n/routing";
  21. import { useWalletStore } from "@/stores/useWalletStore";
  22. import { WalletEnum } from "@/types";
  23. import { copyText, percentage } from "@/utils/methods";
  24. import { Badge, Button, Mask, ProgressBar, Toast } from "antd-mobile";
  25. import clsx from "clsx";
  26. import { useTranslations } from "next-intl";
  27. import Image from "next/image";
  28. import { useEffect, useMemo, useRef, useState } from "react";
  29. type Props = {
  30. userInfo: UserInfoRep;
  31. userMoney: Wallet;
  32. userVip: UserVipInfo;
  33. };
  34. const VipCard = (props: { userVip: UserVipInfo }) => {
  35. const { userVip } = props;
  36. const t = useTranslations("ProfilePage");
  37. const router = useRouter();
  38. // Vip 图标
  39. // const vipIconElement = vipImages.map((item, index) => {
  40. // if (item.leve === userVip?.vip_level) {
  41. // return (
  42. // <Fragment key={index}>
  43. // <Image src={item.src} className="block" alt={"vip"} height={110} width={100} />
  44. // <span className={"icon-level"} style={{ color: item.color }}>
  45. // {item.leve}
  46. // </span>
  47. // </Fragment>
  48. // );
  49. // }
  50. // });
  51. if (!userVip) return null;
  52. return (
  53. <div className={"vip-card"}>
  54. {/* <div className={"vip-card__icon"}>{vipIconElement}</div> */}
  55. <div className={"vip-card-process"}>
  56. {/*<div className={"process-top"}>{userVip.vip_exp}xp</div>*/}
  57. <div className="relative mr-[.1rem] flex-1 px-[.3rem]">
  58. <ProgressBar
  59. percent={percentage(userVip?.vip_exp, userVip?.vip_score_exp)}
  60. style={{
  61. "--fill-color": "#11de68",
  62. "--track-color": "#2b363f",
  63. "--track-width": ".12rem",
  64. }}
  65. />
  66. <div className={"process-bottom text-[#e581ff]"}>
  67. <span className="bg-[#0abd71]">VIP{userVip?.vip_level}</span>
  68. <div className={"process-bottom-desc"}>
  69. {userVip.vip_exp}/{userVip.vip_score_exp}
  70. </div>
  71. <span className="bg-[#eac61f]">
  72. VIP
  73. {userVip.vip_next_level}
  74. </span>
  75. </div>
  76. </div>
  77. <div className="vip-card-text" onClick={() => router.push("/vip")}>
  78. <span className="underline">CLUBE VIP</span>
  79. <i className="iconfont icon-xiangzuo1 block rotate-[180deg]"></i>
  80. </div>
  81. </div>
  82. </div>
  83. );
  84. };
  85. const WalletCard = (props: { userMoney: Wallet }) => {
  86. const { userMoney } = props;
  87. const t = useTranslations("ProfilePage");
  88. const tcdoe = useTranslations();
  89. const tipsRef = useRef<ModalProps>(null);
  90. const [tipsStatus, setTipsStatus] = useState<keyof typeof WalletEnum>("Bonus");
  91. const modalHandler = (key: keyof typeof WalletEnum) => {
  92. setTipsStatus(key);
  93. tipsRef.current?.onOpen();
  94. };
  95. // 未完成游戏
  96. const gameModelRef = useRef<ModalProps>(null);
  97. const game = useRef<(GameListRep & { mode: GameRequest["mode"] }) | null>(null);
  98. // 彩金、免费币、重玩币提现到钱包操作
  99. const handleAcquire = async (wallet_type: number, transfer: boolean) => {
  100. if (!transfer) return;
  101. // 先判断是否有未完成的游戏
  102. const { data }: any = await userInfoApi();
  103. // 如果有未完成游戏 彩金游戏-2、免费游戏-3、重玩游戏-4
  104. if (wallet_type === 2 && data.play_list && data.play_list.length > 0) {
  105. game.current = data.play_list[0];
  106. game.current!.mode = 1;
  107. gameModelRef.current?.onOpen();
  108. return;
  109. }
  110. if (wallet_type === 3 && data.free_game_list && data.free_game_list.length > 0) {
  111. game.current = data.free_game_list[0];
  112. gameModelRef.current?.onOpen();
  113. game.current!.mode = 2;
  114. return;
  115. }
  116. if (wallet_type === 4 && data.lose_game_list && data.lose_game_list.length > 0) {
  117. game.current = data.lose_game_list[0];
  118. game.current!.mode = 3;
  119. gameModelRef.current?.onOpen();
  120. return;
  121. }
  122. getUserTransferApi({ wallet_type })
  123. .then((res) => {
  124. if (res.code === 200) {
  125. Toast.show(tcdoe("code.200"));
  126. setTimeout(() => {
  127. tipsRef.current?.onClose();
  128. }, 1000);
  129. }
  130. })
  131. .catch((error) => {
  132. Toast.show(tcdoe(`code.${error.data.code}`));
  133. });
  134. };
  135. const { getGameUrl } = useGame();
  136. const goGame = () => {
  137. const current = game.current;
  138. getGameUrl(current!, { id: current?.id + "", mode: game.current?.mode! });
  139. tipsRef.current?.onClose();
  140. gameModelRef.current?.onClose();
  141. };
  142. const walletCfg = useMemo(() => {
  143. return [
  144. {
  145. title: t("balance"),
  146. icon: "icon-qianbao3",
  147. onClick: () => modalHandler(WalletEnum.Balance),
  148. value: userMoney.score || "0.0",
  149. key: "balance",
  150. dot: userMoney.is_point_transfer ? Badge.dot : null,
  151. },
  152. {
  153. title: t("bonus"),
  154. icon: "icon-meiyuanzhanghuyue",
  155. onClick: () => modalHandler(WalletEnum.Bonus),
  156. value: userMoney.point || "0.0",
  157. key: "bonus",
  158. dot: userMoney.is_point_transfer ? Badge.dot : null,
  159. },
  160. {
  161. title: t("free"),
  162. icon: "icon-Free-Tag",
  163. onClick: () => modalHandler(WalletEnum.Free),
  164. value: userMoney.free_score || "0.0",
  165. key: "free",
  166. iconStyle: { fontSize: ".22rem" },
  167. dot:
  168. userMoney.is_free_transfer &&
  169. userMoney.free_score >= (userMoney?.free_transfer_min || 0)
  170. ? Badge.dot
  171. : null,
  172. },
  173. {
  174. title: t("replay"),
  175. icon: "icon-meiyuan2",
  176. onClick: () => modalHandler(WalletEnum.Replay),
  177. value: userMoney.lose_score || "0.0",
  178. key: "replay",
  179. dot:
  180. userMoney.is_lose_transfer &&
  181. userMoney.lose_score >= (userMoney?.lose_transfer_min || 0)
  182. ? Badge.dot
  183. : null,
  184. },
  185. ];
  186. }, [userMoney]);
  187. return (
  188. <>
  189. <TipsModal
  190. className="walletModal"
  191. ref={tipsRef}
  192. title={
  193. <div className={"flex items-center text-[#11de68]"}>
  194. <i
  195. className={"iconfont icon-liwuhuodong mr-[0.0694rem] text-[0.2778rem]"}
  196. ></i>
  197. {t("modalTitle")}
  198. </div>
  199. }
  200. >
  201. {/*现金*/}
  202. {tipsStatus === WalletEnum.Balance ? <BalanceContent wallet={userMoney} /> : null}
  203. {/* 彩金*/}
  204. {tipsStatus === WalletEnum.Bonus ? (
  205. <BonusContent wallet={userMoney} handleAcquire={handleAcquire} />
  206. ) : null}
  207. {/* 免费币 */}
  208. {tipsStatus === WalletEnum.Free ? (
  209. <FreeContent wallet={userMoney} handleAcquire={handleAcquire} />
  210. ) : null}
  211. {/* 重玩币 */}
  212. {tipsStatus === WalletEnum.Replay ? (
  213. <ReplayContent wallet={userMoney} handleAcquire={handleAcquire} />
  214. ) : null}
  215. </TipsModal>
  216. {/* 提现拦截 */}
  217. <TipsModal title={"Tips"} ref={gameModelRef}>
  218. <p className={"text-left text-[0.12rem] font-medium text-[#666]"}>
  219. Existem jogos de bônus pendentes que não podem iniciar a retirada.
  220. </p>
  221. <div className={"mt-[0.0694rem] flex justify-center"}>
  222. <Button
  223. color={"primary"}
  224. className={"mx-auto"}
  225. style={{
  226. "--background-color": "var(--primary-color)",
  227. "--border-color": "var(--primary-color)",
  228. }}
  229. onClick={goGame}
  230. >
  231. para jogos
  232. </Button>
  233. </div>
  234. </TipsModal>
  235. <div className="coin">
  236. <div className={"coin_right_wallet"}>
  237. {walletCfg.map((item, index) => {
  238. return (
  239. <div
  240. key={item.key}
  241. className={"wallet_right_content"}
  242. onClick={item.onClick}
  243. >
  244. <Badge
  245. content={item.dot}
  246. style={{
  247. right: "4px",
  248. top: "50%",
  249. width: "6px",
  250. height: "6px",
  251. minWidth: "6px",
  252. }}
  253. >
  254. <div className="wallet-right-icon">
  255. <span
  256. className={clsx("coin_left__icon iconfont", item.icon)}
  257. style={{ ...(item.iconStyle || {}) }}
  258. ></span>
  259. </div>
  260. </Badge>
  261. <section>
  262. <div className={"wallet_header"}>
  263. {item.title}
  264. <div className="wallet-question">?</div>
  265. </div>
  266. <div className="num">
  267. <span className="uppercase">R$</span>
  268. <span>{item.value}</span>
  269. </div>
  270. </section>
  271. </div>
  272. );
  273. })}
  274. </div>
  275. </div>
  276. </>
  277. );
  278. };
  279. const NoBounsWarn = ({ visible, onClose, onConfirm }: any) => {
  280. const doClose = () => {
  281. if (typeof onClose === "function") onClose();
  282. };
  283. const doConfirm = () => {
  284. if (typeof onConfirm === "function") onConfirm();
  285. };
  286. return (
  287. <Mask visible={visible} onMaskClick={doClose}>
  288. <div className="absolute left-[50%] top-[40%] w-[80%] translate-x-[-50%]">
  289. <div className="relative rounded-[.1rem] bg-[#1f2830] px-[.15rem] pb-[.15rem] pt-[0px]">
  290. <div className="h-[.5rem] text-center">
  291. <img
  292. src="/warn_top.png"
  293. alt=""
  294. className="relative -top-[.3rem] inline-block w-[.9rem]"
  295. />
  296. </div>
  297. <div className="text-center text-[.12rem]">
  298. A demanda atual de fluxo de retirada de bônus é excessiva,Se esvaziar o
  299. bônus e retirar a demanda de água corrente?
  300. </div>
  301. <div className="mt-[.2rem] flex items-center justify-between px-[.1rem]">
  302. <button
  303. onClick={doConfirm}
  304. className="mr-[.1rem] h-[.35rem] flex-1 rounded-[60px] bg-[#11de68] text-[.14rem] font-bold text-[#12171a]"
  305. >
  306. A certeza
  307. </button>
  308. <button
  309. onClick={doClose}
  310. className="h-[.35rem] flex-1 rounded-[60px] bg-[#ebc71f] text-[.14rem] font-bold text-[#12171a]"
  311. >
  312. Cancelar
  313. </button>
  314. </div>
  315. <i
  316. className="iconfont icon-guanbi absolute right-[.1rem] top-[.1rem]"
  317. onClick={doClose}
  318. ></i>
  319. </div>
  320. </div>
  321. </Mask>
  322. );
  323. };
  324. export const ProfileHeader = (props: Props) => {
  325. const { userInfo, userVip } = props;
  326. const t = useTranslations("ProfilePage");
  327. const tc = useTranslations();
  328. const { wallet, setWallet } = useWalletStore((state) => ({
  329. wallet: state.wallet,
  330. setWallet: state.setWallet,
  331. }));
  332. const router = useRouter();
  333. const [isShowNoBounsWarn, setIsShowNoBounsWarn] = useState(false);
  334. const [isShowed, setIsShowed] = useState(false);
  335. useEffect(() => {
  336. const curMul = wallet.target_point_rollover / ((wallet?.score || 0) + (wallet.point || 0));
  337. const config = wallet.no_bonus_config;
  338. if (curMul >= (config || 0) && !isShowed) {
  339. setIsShowNoBounsWarn(true);
  340. setIsShowed(true);
  341. }
  342. }, [wallet]);
  343. const handler = () => {
  344. if (!!wallet.score) {
  345. router.push("/deposit?target=2");
  346. } else {
  347. Toast.show("no money");
  348. }
  349. };
  350. const doConfirm = async () => {
  351. Toast.show({
  352. icon: "loading",
  353. maskClickable: false,
  354. });
  355. setIsShowNoBounsWarn(false);
  356. const res = await cleanBounsApi(1);
  357. if (res?.code && [6001, 6002].includes(res?.data?.code)) {
  358. const str = t(`bouns${res?.data?.code}`);
  359. Toast.show({
  360. content: str,
  361. icon: "fail",
  362. });
  363. }
  364. Toast.show({
  365. content: t("success"),
  366. icon: "success",
  367. });
  368. const walletRes = await getUserMoneyApi();
  369. setWallet(walletRes?.data);
  370. };
  371. const doCopyUsreId = () => {
  372. copyText(userInfo?.user_phone || "");
  373. Toast.show({ icon: "success", content: tc("SummaryPage.copySuc"), maskClickable: false });
  374. };
  375. return (
  376. <>
  377. <div className={"userContent"}>
  378. <div className={"userInfo"}>
  379. <div>
  380. <div className={"bgImg"}>
  381. <Image
  382. src={"/img/avatar.png"}
  383. className={"h-[100%] w-[100%]"}
  384. alt={"avatar"}
  385. width={120}
  386. height={120}
  387. />
  388. </div>
  389. <div>
  390. <span className="font-bold">{t("Conta")}</span>
  391. <div className="flex items-center">
  392. <span className="phone text-[#7b939a]">
  393. {userInfo?.user_phone || ""}
  394. </span>
  395. <i
  396. className="iconfont icon-fuzhi1 text-[#7b939a]"
  397. onClick={doCopyUsreId}
  398. ></i>
  399. </div>
  400. </div>
  401. </div>
  402. {/* <Link
  403. className="goto iconfont icon-xiangzuo1 text-[#7b939a]"
  404. href={`/changePassword`}
  405. ></Link> */}
  406. </div>
  407. {/*vipcard*/}
  408. <VipCard userVip={userVip} />
  409. <WalletCard userMoney={wallet} />
  410. </div>
  411. <div className="link">
  412. <Link href={"/deposit"} className={"btn"}>
  413. <i className="iconfont icon-meiyuanzhanghuyue mr-[.1rem]"></i>
  414. <span>{t("Depósito")}</span>
  415. </Link>
  416. <p className={"btn"} onClick={handler}>
  417. <i className="iconfont icon-zhuishou-meiyuan-shi mr-[.1rem]"></i>
  418. <span>{t("Sacar")}</span>
  419. </p>
  420. </div>
  421. <NoBounsWarn
  422. visible={isShowNoBounsWarn} // 控制是否显示遮罩层,true 显示,false 不显示
  423. onClose={() => setIsShowNoBounsWarn(false)}
  424. onConfirm={doConfirm}
  425. ></NoBounsWarn>
  426. </>
  427. );
  428. };